﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace SemenQuest
{
    public static class MathUtils
    {
        public static Double HorizontalAngleOut(Point newLocation, Point oldLocation)
        {
            return 180 - (Math.Atan2(newLocation.Y - oldLocation.Y, newLocation.X - oldLocation.X) - Math.Atan2(0, 1)) * 180 / Math.PI;
        }

        public static Double VerticalAngleOut(Point newLocation, Point oldLocation)
        {
            return -(Math.Atan2(newLocation.Y - oldLocation.Y, newLocation.X - oldLocation.X) - Math.Atan2(0, 1)) * 180 / Math.PI;
        }

        public static Point NewLocation(Point oldLocation, Double angle, Double velocity)
        {
            return new Point()
            {
                X = oldLocation.X + (Int32)((velocity) * Math.Cos((Math.PI / 180) * angle)),
                Y = oldLocation.Y + (Int32)((velocity) * Math.Sin((Math.PI / 180) * angle))
            };
        }

        public static Double AngleTowardTarget(Point Location, Point TargetLocation)
        {
            double deltaY = TargetLocation.Y - Location.Y;
            double deltaX = TargetLocation.X - Location.X;

            double t = Math.Atan2(deltaY, deltaX) * 180 / Math.PI;
            double y = (t + 360) % 360;
            return y;
        }

        public static Double DistanceToTarget(Point Location, Point TargetLocation)
        {
            return Math.Sqrt(
                Math.Pow((Location.X - TargetLocation.X), 2) +
                Math.Pow((Location.Y - TargetLocation.Y), 2));
        }

        public static Double AngleDifference(Double Angle1, Double Angle2)
        {
            return Math.Abs(Math.Abs(Angle1 - Angle2 + 180) % 360 - 180);
        }
    }
}
